﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;

namespace SharPy.Interface
{
    class clDialogs
    {
        public static async Task<bool> Error(string message, string title = "Error")
        {
            MessageDialog md = new MessageDialog(message);
            md.Title = title;
            await md.ShowAsync();
            return false;
        }

        public static async Task<bool> RefreshGameList()
        {
            MessageDialog RefreshDialog = new MessageDialog("Problem loading xml data. Refresh game list?");
            RefreshDialog.Commands.Add(new UICommand("Yes", null, 0));
            RefreshDialog.Commands.Add(new UICommand("No", null, 1));
            RefreshDialog.Title = "Game list is incorrect.";
            var result = await RefreshDialog.ShowAsync();

            if ((int)result.Id == 0)
                return true;
            else 
                return false;
        }

        public static async Task<bool> QuitGame()
        {
            MessageDialog quitConfirm = new MessageDialog("Are you sure you want to quit? Game will be saved at current position.");
            quitConfirm.Commands.Add(new Windows.UI.Popups.UICommand("Yes", null, 0));
            quitConfirm.Commands.Add(new Windows.UI.Popups.UICommand("No", null, 1));
            quitConfirm.Title = "Exit current game";
            var result = await quitConfirm.ShowAsync();

            if ((int)result.Id == 0)
            {
                return true;
            }
            return false;
        }

        internal async static Task<bool> OverwriteSave()
        {
            MessageDialog Confirm = new MessageDialog("Save already exists. Overwrite?");
            Confirm.Commands.Add(new Windows.UI.Popups.UICommand("Yes", null, 0));
            Confirm.Commands.Add(new Windows.UI.Popups.UICommand("No", null, 1));
            Confirm.Title = "Save exists";
            var result = await Confirm.ShowAsync();

            if ((int)result.Id == 0)
            {
                return true;
            }
            return false;            
        }

        internal async static Task<bool> CorruptSave()
        {
            MessageDialog quitConfirm = new MessageDialog("Save file is corrupt. Recreate?");
            quitConfirm.Commands.Add(new Windows.UI.Popups.UICommand("Yes", null, 0));
            quitConfirm.Commands.Add(new Windows.UI.Popups.UICommand("No", null, 1));
            quitConfirm.Title = "File IO error";
            var result = await quitConfirm.ShowAsync();

            if ((int)result.Id == 0)
            {
                return true;
            }
            return false;
        }

        internal static async void SaveSuccess()
        {
            MessageDialog Success = new MessageDialog("Save successful");
            Success.ShowAsync();
        }

        internal async static Task<bool> SaveFileCorrupt()
        {
            MessageDialog Dialog = new MessageDialog("Save file seems to be broken. Re-create?");
            Dialog.Commands.Add(new UICommand("Yes", null, 0));
            Dialog.Commands.Add(new UICommand("No", null, 1));
            Dialog.Title = "Save file is incorrect.";
            var result = await Dialog.ShowAsync();

            if ((int)result.Id == 0)
                return true;
            else
                return false;
        }

        internal static async Task<bool> DeleteGame(string name)
        {
            MessageDialog Dialog = new MessageDialog("Do you want to delete " + name +"?");
            Dialog.Commands.Add(new UICommand("Yes", null, 0));
            Dialog.Commands.Add(new UICommand("No", null, 1));
            Dialog.Title = "Delete game.";
            var result = await Dialog.ShowAsync();

            if ((int)result.Id == 0)
                return true;
            else
                return false;
        }
    }
}
